package com.aerospace.module.lyric;

import com.aerospace.model.Player;
import com.aerospace.module.lyric.baidu.BaiduLyricLoader;
import com.aerospace.module.lyric.model.Lyric;
import com.aerospace.module.lyric.qq.QQLyricLoader;
import com.aerospace.util.NumberUtils;
import com.aerospace.util.StrUtils;

/**
 * @ClassName LyricManager
 * @Description TODO
 * @Author Aero
 * @Date 2019/10/7 19:52
 * @Version 1.0
 **/
public class LyricManager {

    private static final BaiduLyricLoader baidu = new BaiduLyricLoader();
    private static final QQLyricLoader qq = new QQLyricLoader();

    /**
     * 先通过baidu查询，再通过qq查询
     *
     * @return
     */
    public static Lyric load(Player player) {
        System.out.println("lyricManager");
        if (StrUtils.isEmpty(StrUtils.trim(player.getTitle())) //
                || StrUtils.isEmpty(StrUtils.trim(player.getArtist()))) {
            return null;
        }

        Lyric lyric = baidu.load(player);

        if (NumberUtils.parseInt(lyric.getInfo()) >= 0 // 百度查询成功,直接返回
                && lyric.getLyricItems().size() > 0) {
            return lyric;
        }

        lyric = qq.load(player);

        if (NumberUtils.parseInt(lyric.getInfo()) >= 0 // qq查询成功,直接返回
                || lyric.getLyricItems().size() > 0) {
            return lyric;
        }

        return null;
    }
}
